Repository navigation
Conversation
The test suite builds throwaway repositories and compares git's answers
against the values it set up itself. A url.<base>.insteadOf rewrite in
the developer's ~/.gitconfig or system configuration changes those
answers, because git remote -v prints the rewritten URL, so
baseline::tests::test_fork_origin_uses_configured_project fails on any
machine that clones GitHub over SSH:
left: RemoteTarget { url: "git@github.com:contributor/renamed-tree.git" }
right: RemoteTarget { url: "https://github.com/contributor/renamed-tree.git" }
Production code has to honour the caller's configuration: it decides
which credentials a fetch uses and which URL a remote really points at,
so the isolation is restricted to test builds. There the git_command!
macro points GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM at /dev/null, and
every git command built here reads the repository's own configuration
and nothing else.
Closes: sashiko-dev#897
Signed-off-by: Sendao Yan <yansendao@126.com>
Sashiko review✓ No issues found across 1 commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
make check-prfails on any developer machine whose global git config rewritesGitHub URLs:
git remote -vappliesurl.<base>.insteadOf, so a[url "git@github.com:"]block turns the
https://github.com/...URL a fixture added intogit@github.com:..., and the assertion compares two different strings. CInever sees it because the runner has no such configuration.
Fixes #897.
Changes
git_cmdis the single place every git command in the crate is built, and italready strips the
GIT_DIRfamily so that an inherited environment cannotredirect a command at another repository. This extends the same idea to the
configuration files:
TEST_CONFIG_FILES(#[cfg(test)]) namesGIT_CONFIG_GLOBALandGIT_CONFIG_SYSTEM, both set to/dev/null.git_command!applies them to everyin_dir,in_dir_asyncanddetached_asynccommand in test builds.Production code keeps honouring the caller's configuration, which decides
which credentials a fetch uses and which URL a remote really points at. Only
the tests, which build throwaway repositories and compare git's answers
against the values they set up themselves, are isolated.
test_commands_read_only_the_repository_configurationasserts both variableson all three constructors.
Testing
make check-pron a machine whose~/.gitconfigcontains the reproducinginsteadOfblock: all tests pass (1758 lib tests, plus the binary andintegration suites).
baseline::tests::test_fork_origin_uses_configured_projectfails at
src/baseline.rs:2462withgit@github.com:contributor/renamed-tree.giton the left andhttps://github.com/contributor/renamed-tree.giton the right.